package home;

import java.math.BigDecimal;

import items.BigStockable;
import items.BrandDTO;
import items.Service;
import items.Stockable;

import org.apache.wicket.Page;
import org.apache.wicket.authroles.authentication.AbstractAuthenticatedWebSession;
import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;

import services.GeneralService;
import services.StockableService;

public class MyApplication extends AuthenticatedWebApplication{
	
	private MounterURL aMounterURL;
	
    private GeneralService generalService;

	@Override
	protected Class<? extends WebPage> getSignInPageClass() {
		 return Home.class;
	}

	@Override
	protected Class<? extends AbstractAuthenticatedWebSession> getWebSessionClass() {
		 return WebSession.class;
	}

	@Override
	public Class<? extends Page> getHomePage() {
		 return Home.class;
	}
	
	public String getContextPath() {
	    return this.getServletContext().getContextPath();
	}
	
    @Override
    public void init() {
        aMounterURL = new MounterURL(this);
        // Linea magica //
        this.getComponentInstantiationListeners().add(new SpringComponentInjector(this));
        // ////////////////
        this.mountUrl("home", Home.class, "");
        this.createServices();
        this.createAccessories();
        this.createBrandsModels();
        this.createTires();
    }
    
    private void mountUrl(final String mountPath, final Class<? extends WebPage> pageClass, final String... parameters) {
    	aMounterURL.mount(mountPath, pageClass, parameters);
    }

	private void createTires() {
		StockableService serv = this.generalService.getStockableSer();
		serv.save(new Stockable("Neumatico","Pirelli","Cinturato P7","165/60/14",new BigDecimal("120"),15.0,30.0));
		serv.save(new Stockable("Neumatico","Pirelli","Cinturato P6","165/40/14",new BigDecimal("100"),15.0,30.0));
	}

	private void createBrandsModels() {
		this.generalService.getBrandSer().save(new BrandDTO("A","- - -","- - -"));
		this.generalService.getBrandSer().save(new BrandDTO("A","Ford","Fiesta"));
		this.generalService.getBrandSer().save(new BrandDTO("A","Fiat","Uno"));
		this.generalService.getBrandSer().save(new BrandDTO("A","Chevrolet","Camaro"));
		this.generalService.getBrandSer().save(new BrandDTO("N","Pirelli","Cinturato P7"));
		this.generalService.getBrandSer().save(new BrandDTO("N","Pirelli","Cinturato P6"));
	}

    
    private void createServices() {
        Service alineacion = new Service("Alineacion",new BigDecimal("180"));
        Service balanceo = new Service("Balanceo",new BigDecimal("35"));
        Service comba = new Service("Comba",new BigDecimal("40"));
        Service rotacion = new Service("Rotacion",new BigDecimal("35"));
        Service armedesarme = new Service("Arme/Desarme",new BigDecimal("60"));
        this.generalService.getServiceSer().save(alineacion);
        this.generalService.getServiceSer().save(balanceo);
        this.generalService.getServiceSer().save(comba);
        this.generalService.getServiceSer().save(rotacion);
        this.generalService.getServiceSer().save(armedesarme);
	}
    
    private void createAccessories() {
    	Stockable bulon = new Stockable("Bulon","Fiat","Uno","5''",new BigDecimal("30"),10.0,15.0);
    	Stockable cubrebulon = new Stockable("Cubre Bulon","- - -"," - - -","5''",new BigDecimal("30"),10.0,15.0);
    	Stockable graceras = new Stockable("Gracera","Fiat","Uno","- - -",new BigDecimal("30"),10.0,15.0);
    	Stockable tasitas = new Stockable("Tasita Plastica","Fiat","Uno","- - -",new BigDecimal("30"),10.0,15.0);
    	Stockable clliso = new Stockable("Centro Llanta Liso","Fiat","Uno","- - -",new BigDecimal("30"),10.0,15.0);
    	Stockable cllogo = new Stockable("Centro Llanta Logo","Fiat","Uno","- - -",new BigDecimal("30"),10.0,15.0);
    	Stockable separadores = new Stockable("Separador","Fiat","- - -","- - -",new BigDecimal("30"),10.0,15.0);
    	Stockable logo = new Stockable("Logo","Fiat","- - -","5''",new BigDecimal("30"),10.0,15.0);
    	Stockable camara = new Stockable("Camara","- - -","- - -","5''",new BigDecimal("30"),10.0,15.0);
    	this.generalService.getStockableSer().save(bulon);
    	this.generalService.getStockableSer().save(graceras);
    	this.generalService.getStockableSer().save(cubrebulon);
    	this.generalService.getStockableSer().save(tasitas);
    	this.generalService.getStockableSer().save(clliso);
    	this.generalService.getStockableSer().save(cllogo);
    	this.generalService.getStockableSer().save(separadores);
    	this.generalService.getStockableSer().save(logo);
    	this.generalService.getStockableSer().save(camara);
    	
    	
    }


	//-----------Gett&Sett------------
	
	public GeneralService getGeneralService() {
		return generalService;
	}

	public void setGeneralService(GeneralService generalService) {
		this.generalService = generalService;
	}

	public MounterURL getaMounterURL() {
		return aMounterURL;
	}

	public void setaMounterURL(MounterURL aMounterURL) {
		this.aMounterURL = aMounterURL;
	}

}
